/*
 * common_types.h
 *
 *  Created on: 2016年4月14日
 *      Author: guyadong
 */

#ifndef FACEDETECT_CL_FILES_COMMON_TYPES_H_
#define FACEDETECT_CL_FILES_COMMON_TYPES_H_
#ifdef __OPENCL_VERSION__
typedef char	cl_char;
typedef uchar	cl_uchar;
typedef short	cl_short;
typedef ushort	cl_ushort;
typedef int		cl_int;
typedef uint	cl_uint;

typedef long	cl_long;
typedef ulong	cl_ulong;

typedef double	cl_double;
typedef float	cl_float;

typedef char2		cl_char2;
typedef char4 		cl_char4;
typedef char8 		cl_char8;
typedef char16		cl_char16;

typedef uchar2		cl_uchar2;
typedef uchar4 		cl_uchar4;
typedef uchar8 		cl_uchar8;
typedef uchar16		cl_uchar16;

typedef short2		cl_short2;
typedef short4 		cl_short4;
typedef short8 		cl_short8;
typedef short16		cl_short16;

typedef ushort2		cl_ushort2;
typedef ushort4 	cl_ushort4;
typedef ushort8 	cl_ushort8;
typedef ushort16	cl_ushort16;

typedef int2		cl_int2;
typedef int4 		cl_int4;
typedef int8 		cl_int8;
typedef int16		cl_int16;

typedef uint2		cl_uint2;
typedef uint4 		cl_uint4;
typedef uint8 		cl_uint8;
typedef uint16		cl_uint16;

typedef long2		cl_long2;
typedef long4 		cl_long4;
typedef long8 		cl_long8;
typedef long16		cl_long16;

typedef ulong2		cl_ulong2;
typedef ulong4 		cl_ulong4;
typedef ulong8 		cl_ulong8;
typedef ulong16		cl_ulong16;

typedef float2		cl_float2;
typedef float4		cl_float4;
typedef float8		cl_float8;
typedef float16		cl_float16;

typedef double2		cl_double2;
typedef double4		cl_double4;
typedef double8		cl_double8;
typedef double16	cl_double16;
#ifdef NDEBUG
#define DEBUG_LOG(format, ...) 
#else
#define DEBUG_LOG(format, ...) printf((__constant char*)format, __VA_ARGS__)
#endif
#define LOG(format, ...) printf((__constant char*)format, __VA_ARGS__)
#ifndef NULL
#define NULL 0
#endif

#define _VECTOR(t,n) t##n
#define VECTOR(t,n) _VECTOR(t,n)

#define _FUN_NAME(f,n) f##n
#define FUN_NAME(f,n) _FUN_NAME(f,n)
#define _FUN_NAME2(f,n,s) f##_##n##s
#define FUN_NAME2(f,n,s) _FUN_NAME2(f,n,s)

#define VCONVERT(vtype,suffix) FUN_NAME2(convert,vtype,suffix)
#define VCONVERT_SAT(vtype) VCONVERT(vtype,_sat)
#define VAS(vtype) FUN_NAME2(as,vtype,)
#define ALIGN_UP(v,a) ((v+(1<<a)-1)>>a<<a)
//denominator/numerator
#define CEIL_DIV(d,n) (((d)+(n)-1)/(n))

#endif

// define alignment macro for data struct crossed between host & device
#ifdef _MSC_VER
#define _CL_CROSS_ALIGN_(n) __declspec( align(n) )
#elif __GNUC__
#define _CL_CROSS_ALIGN_(n) __attribute__((aligned(n)))
#elif __cplusplus>=201103L
#define _CL_CROSS_ALIGN_(n) alignas(n)
#elif __OPENCL_VERSION__
#define _CL_CROSS_ALIGN_(n) __attribute__((aligned(n)))
#else
#warning  Need to implement some method to align data here
#define _CL_CROSS_ALIGN_(n)
#endif /*_MSC_VER*/

// define column num of each work-item working for integral kernel,
// is also equivalent to the number of local work-items so sad get_local_size(0)
#define	INTEGRAL_COLUMN_STEP 16
#define	IMGSCALE_LOCAL_SIZE 64
/* get divisor for len/num */
inline size_t gf_get_divisor(size_t len,size_t num){
	return (size_t)(len/num+(int)(len%num>0));
}
typedef struct _integ_param {
	cl_int width,height,src_width_step,dst_width_step;
}integ_param;
typedef struct _matrix_info_cl {
	cl_uint		width	;
	cl_uint		height	;
	cl_uint		row_stride;
/*
#ifdef __cplusplus
	_matrix_info_cl(size_t width,size_t height,size_t row_stride=0):width(cl_uint(width)), height(cl_uint(width)),row_stride( cl_uint(row_stride? row_stride:width)) {}
	_matrix_info_cl() = default;
	_matrix_info_cl(const _matrix_info_cl&) = default;
	_matrix_info_cl(_matrix_info_cl&&) = default;
	_matrix_info_cl& operator=(const _matrix_info_cl&) = default;
	_matrix_info_cl& operator=(_matrix_info_cl&&) = default;
#endif
*/
}matrix_info_cl;
// define integral matrix type
//  default intergal matrix
#define INTEG_DEFAULT	0
//  intergal matrix for suquare
#define INTEG_SQUARE	1
//  integral matrix for count of no zero
#define INTEG_COUNT		2
typedef enum _integral_type{
	integ_default=INTEG_DEFAULT
	,integ_square=INTEG_SQUARE
	,integ_count=INTEG_COUNT
}integral_type;

#endif /* FACEDETECT_CL_FILES_COMMON_TYPES_H_ */
